<!doctype html>
<head>
	<title>Go wasm</title>
</head>

<body>
	<script src="c2d.js"></script>
	<script src="wasm_exec.js"></script>
	<script src="index.js"></script>

	<button onClick="run();" id="runButton" disabled>Run</button>

	<canvas id="nes" tabindex="0"></canvas>


	<script>
		function test(){
			var w = 240;
			var h = 256;
			var buf = new ArrayBuffer(w * h * 4);
			var p = new Uint8ClampedArray(buf);
			for (var y = 0; y < h; y++){
				for (var x = 0; x < w; x++){
					p[(y * w + x) * 4] = 255;
					p[(y * w + x) * 4 + 1] = 0;
					p[(y * w + x) * 4 + 2] = 0;
					p[(y * w + x) * 4 + 3] = 255;
				}
			}
			jsSetPixels("nes", p, w, h);
		}
		test()

		function canvase_onKeyDown(event) {
			goKeyDown(event.key);
		}
		function canvase_onKeyUp(event) {
			goKeyUp(event.key);
		}
		var canvas = document.getElementById('nes');
		canvas.addEventListener("keydown", canvase_onKeyDown, true);
		canvas.addEventListener("keyup", canvase_onKeyUp, true);
		canvas.focus();
    </script>
</body>
